<switch name="addons_config.editor_type">
<case value="1">
    {// 纯文本 }
    <input type="hidden" name="parse" value="0">
    <script type="text/javascript">
        $('textarea[name="{$addons_data.name}"]').height('{$addons_config.editor_height}');</script>
</case>
<case value="2">
    {// 富文本 }
    <input type="hidden" name="parse" value="0">
    <eq name="addons_config.editor_wysiwyg" value="1">
    <link rel="stylesheet" href="__STATIC__/kindeditor/default/default.css" />
    <script charset="utf-8" src="__STATIC__/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="__STATIC__/kindeditor/zh_CN.js"></script>
    <script type="text/javascript">
        var editor;
        KindEditor.ready(function(K) {
        editor = K.create('textarea[name="{$addons_data.name}"]', {
        allowFileManager : false,
                themesPath: K.basePath,
                width: '100%',
                height: '{$addons_config.editor_height}',
                resizeType: <eq name="addons_config.editor_resize_type" value="1">1<else />0</eq>,
                pasteType : 2,
                urlType : 'absolute',
                fileManagerJson : '{:U('fileManagerJson')}',
                //uploadJson : '{:U('uploadJson')}' }
                uploadJson : '{:addons_url("EditorForAdmin://Upload/ke_upimg")}'
        });
        });
        $(function(){
            //传统表单提交同步
            $('textarea[name="{$addons_data.name}"]').closest('form').submit(function(){
                var $textarea = $('textarea[name="{$addons_data.name}"]');
                // 如果编辑器中有图片，检查图片
                var $outerImgs = $("img", $textarea.closest('form'));
                var count = $outerImgs.length;
                console.log(count);
                if( count > 0 ){
                    updateAlert('正在保存远程图片','success');
                    $.each($outerImgs, function(index, val) {
                        var url = $outerImgs[index].src;
                        console.log(url);
                        console.log(val);
                        count--;
                        if(count>1){
                            editor.sync();
                            updateAlert('还有'+ (count-1) + '张远程图片待处理','success');
                        }else{
                            updateAlert('成功','success');
                        }
                    });
                }else{
                    editor.sync();
                }
                return false;
            });
            //ajax提交之前同步
            $('button[type="submit"],#submit,.ajax-post').click(function(){
                var $textarea = $('textarea[name="{$addons_data.name}"]');
                // 如果编辑器中有图片，检查图片
                var $outerImgs = $(".ke-edit-iframe").contents().find("img");
                var count = $outerImgs.length;
                console.log(count);
                if( count > 0 ){
                    updateAlert('正在保存远程图片','success');
                    $.each($outerImgs, function(index, val) {
                        var url = $outerImgs[index].src;
                        console.log(url);
                        console.log(val);
                        count--;
                        if(count >0){
                            editor.sync();
                            updateAlert('还有'+ (count-1) + '张远程图片待处理','success');
                        }else{
                            updateAlert('成功','success');
                        }
                    });
                }else{
                    editor.sync();
                }
                return false;
            });
        })
    </script>

    <else />
    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.js"></script>
    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        $('textarea[name="{$addons_data.name}"]').attr('id', 'editor_id_{$addons_data.name}');
        window.UEDITOR_HOME_URL = "__STATIC__/ueditor";
        window.UEDITOR_CONFIG.initialFrameHeight = parseInt('{$addons_config.editor_height}');
        window.UEDITOR_CONFIG.scaleEnabled = <eq name = "addons_config.editor_resize_type" value="1">true<else />false</eq>;
        window.UEDITOR_CONFIG.imageUrl = '{:addons_url("EditorForAdmin://Upload/ue_upimg")}';
        window.UEDITOR_CONFIG.imagePath = '';
        window.UEDITOR_CONFIG.imageFieldName = 'imgFile';
        UE.getEditor('editor_id_{$addons_data.name}');
    </script>
    </eq>
</case>
<case value="4">
    {// markdown }
    <link rel="stylesheet" href="__ADDONROOT__/thinkeditor/skin/default/style.css">
    <script type="text/javascript" src="__PUBLIC__/js/Migrate.js"></script>
    <script type="text/javascript" src="__ADDONROOT__/marked.js"></script>
    <script type="text/javascript" src="__ADDONROOT__/thinkeditor/jquery.thinkeditor.js"></script>
    <script type="text/javascript">
        $(function(){
            $('textarea[name="{$addons_data.name}"]').attr('id', 'editor_id_{$addons_data.name}');
            var options = {
            "items"  : "h1,h2,h3,h4,h5,h6,-,link,image,-,bold,italic,code,-,ul,ol,blockquote,hr,-,fullscreen",
                    "width"  : "100%", //宽度
                    "height" : "{$addons_config.editor_height}", //高度
                    "lang"   : "zh-cn", //语言
                    "tab"    : "    ", //Tab键插入的字符， 默认为四个空格
                    "uploader": "{:addons_url('Editor://Upload/upload')}",
                    "preview": {$addons_config.editor_markdownpreview}
            };
            $('#editor_id_{$addons_data.name}').thinkeditor(options);
        })
    </script>
    <input type="hidden" name="parse" value="2">
</case>
</switch>
